package com.paomi.client.activity.person.presenter;

import android.app.Activity;
import android.content.DialogInterface;

import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
import com.hannesdorfmann.mosby3.mvp.MvpView;
import com.paomi.client.activity.person.View.IntegralRecordView;
import com.paomi.client.activity.person.model.IntegralListBean;
import com.paomi.client.bean.BaseJSON;
import com.paomi.client.net.Api;
import com.paomi.client.net.BaseCallback;
import com.paomi.client.net.Constants;
import com.paomi.client.utils.Datas;
import com.paomi.client.view.wheel.ChooseDateDialog;
import com.paomi.client.view.wheel.dialog.ChangeDateDialog;

import java.util.HashMap;

import retrofit2.Call;

public class IntegralRecordPre extends MvpBasePresenter<IntegralRecordView> {
    ChooseDateDialog.Builder dialog;//选择日期的滑轮

    public void getIntegralList(String year,String month,int page) {
        HashMap<String, String> map = new HashMap<>();
        map.put("pageNum", "" + page);
        map.put("pageSize", "" + Constants.PAGE_SIZE);
        map.put("year", "" + year);
        map.put("month", "" + month);
        Api.getInstanceService(Constants.User_URL).getIntegralList(map).enqueue(new BaseCallback<IntegralListBean>() {
            @Override
            public void onResponse(Call<IntegralListBean> call, IntegralListBean result) {
                getView().showIntegralList(result);
            }
        });
    }

    /**
     * 选择年月
     *
     * @param
     */
    public void selectDate(Activity activity) {
        dialog = new ChooseDateDialog.Builder(activity);
        dialog.setDate(Datas.getDateYear(), Datas.getTimesYue(), Datas.getRiQi());
        dialog.setBirthdayListener(new ChooseDateDialog.Builder.OnBirthListener() {
            @Override
            public void onClick(String year, String month, String day) {
                StringBuilder sb = new StringBuilder();
                sb.append(year.substring(0, year.length() - 1)).append("-").append(month.substring(0, day.length() - 1)).append("-").append(day);
                if (year.contains("年")) {
                    year = year.substring(0, year.length() - 1);
                }
                if (month.contains("月")) {
                    month = month.substring(0, month.length() - 1);
                }

                getView().showData(year + "", "" + month);
            }
        });
        dialog.setClickListenerCancel(new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.create().show();
    }
}
